﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Input;

namespace Remember
{
    public class Commands
    {
        public AddNoteCommand AddNote { get; private set; }
        public OpenAddNoteWindowCommand OpenAddNoteWindow { get; private set; }

        public Commands(MainWindowViewModel mainModel)
        {
            AddNote = new AddNoteCommand(mainModel);
            OpenAddNoteWindow = new OpenAddNoteWindowCommand(mainModel);
        }
    }

    public class AddNoteCommand : ICommand
    {
        private MainWindowViewModel mainModel;

        public AddNoteCommand(MainWindowViewModel mainModel)
        {
            this.mainModel = mainModel;
        }

        public bool CanExecute(object parameter)
        {
 	        return true;
        }

        public event EventHandler CanExecuteChanged;

        public void Execute(object parameter)
        {
            Note note = OpenAddNoteWindowCommand.addNoteModel.Note;

            mainModel.NotesManager.AddNote(note);
            mainModel.Refresh();
            mainModel.TrayManager.ShowBalloon("Note Added");
        }
    }

    public class OpenAddNoteWindowCommand : ICommand
    {
        public static AddNoteViewModel addNoteModel;

        private MainWindowViewModel mainModel;

        public OpenAddNoteWindowCommand(MainWindowViewModel mainModel)
        {
            this.mainModel = mainModel;
        }

        public bool CanExecute(object parameter)
        {
            return true;
        }

        public event EventHandler CanExecuteChanged;

        public void Execute(object parameter)
        {
            Remember.Views.AddNoteWindow addWindow = new Views.AddNoteWindow();
            AddNoteViewModel addModel = new AddNoteViewModel(mainModel);
            addWindow.DataContext = addModel;
            addWindow.Show();
            addNoteModel = addModel;
        }
    }
}
